home *** CD-ROM | disk | FTP | other *** search
/ Mastering Web Site Development / Microsoft Mastering Web Site Development (Microsoft) (1997).iso / Media / SampApps / AdvWorks / AWVB5Demo.EXE / AWCust_Form.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1997-04-07  |  5.9 KB  |  176 lines

  1. VERSION 5.00
  2. Begin VB.Form TestForm 
  3.    Caption         =   "TestForm for Customer and Customers objects"
  4.    ClientHeight    =   2715
  5.    ClientLeft      =   1770
  6.    ClientTop       =   3780
  7.    ClientWidth     =   6405
  8.    LinkTopic       =   "Form1"
  9.    PaletteMode     =   1  'UseZOrder
  10.    ScaleHeight     =   2715
  11.    ScaleWidth      =   6405
  12.    WhatsThisHelp   =   -1  'True
  13.    Begin VB.CommandButton cmdExit 
  14.       Caption         =   "Exit"
  15.       Height          =   495
  16.       Left            =   4080
  17.       TabIndex        =   6
  18.       Top             =   2040
  19.       Width           =   2175
  20.    End
  21.    Begin VB.CommandButton cmdGetNextCustomers 
  22.       Caption         =   "Get Next Customers"
  23.       Enabled         =   0   'False
  24.       Height          =   495
  25.       Left            =   2160
  26.       TabIndex        =   5
  27.       Top             =   2040
  28.       Width           =   1815
  29.    End
  30.    Begin VB.CommandButton cmdGetFirstCustomer 
  31.       Caption         =   "Get First Customer"
  32.       Enabled         =   0   'False
  33.       Height          =   495
  34.       Left            =   2160
  35.       TabIndex        =   4
  36.       Top             =   1440
  37.       Width           =   1815
  38.    End
  39.    Begin VB.CommandButton cmdLookupByID 
  40.       Caption         =   "Lookup by ID"
  41.       Enabled         =   0   'False
  42.       Height          =   495
  43.       Left            =   2160
  44.       TabIndex        =   3
  45.       Top             =   840
  46.       Width           =   1815
  47.    End
  48.    Begin VB.CommandButton cmdLookupByLastName 
  49.       Caption         =   "Lookup by Last Name"
  50.       Enabled         =   0   'False
  51.       Height          =   495
  52.       Left            =   2160
  53.       TabIndex        =   2
  54.       Top             =   240
  55.       Width           =   1815
  56.    End
  57.    Begin VB.CommandButton cmdReleaseObjects 
  58.       Caption         =   "Release Customer Object"
  59.       Enabled         =   0   'False
  60.       Height          =   495
  61.       Left            =   4080
  62.       TabIndex        =   1
  63.       Top             =   240
  64.       Width           =   2175
  65.    End
  66.    Begin VB.CommandButton cmdCreateObjects 
  67.       Caption         =   "Create Customer Object"
  68.       Height          =   495
  69.       Left            =   120
  70.       TabIndex        =   0
  71.       Top             =   240
  72.       Width           =   1935
  73.    End
  74. Attribute VB_Name = "TestForm"
  75. Attribute VB_GlobalNameSpace = False
  76. Attribute VB_Creatable = False
  77. Attribute VB_PredeclaredId = True
  78. Attribute VB_Exposed = False
  79. Option Explicit
  80. Dim myCustomer As ADODB.Recordset
  81. Dim myCustomers As AWCustomer.Customers
  82. Private Sub DumpCustomer()
  83.     Dim strDump As String
  84.     Dim NL As String
  85.     On Error GoTo onError
  86.     ' build up string with text description of each property
  87.     NL = Chr(13) + Chr(10)
  88.     strDump = "CustomerID = " & myCustomer.Fields("CustomerID").Value
  89.     strDump = strDump & NL & "CustomerFirstName = " & myCustomer.Fields("CustomerFirstName").Value
  90.     strDump = strDump & NL & "CustomerLastName= " & myCustomer.Fields("CustomerLastName").Value
  91.     strDump = strDump & NL & "BillingAddress= " & myCustomer.Fields("BillingAddress").Value
  92.     strDump = strDump & NL & "City = " & myCustomer.Fields("City").Value
  93.     strDump = strDump & NL & "StateOrProvince = " & myCustomer.Fields("StateOrProvince").Value
  94.     strDump = strDump & NL & "PostalCode = " & myCustomer.Fields("PostalCode").Value
  95.     strDump = strDump & NL & "Country = " & myCustomer.Fields("Country").Value
  96.     strDump = strDump & NL & "PhoneNumber = " & myCustomer.Fields("PhoneNumber").Value
  97.     strDump = strDump & NL & "EmailAddress = " & myCustomer.Fields("EmailAddress").Value
  98.     MsgBox strDump
  99.     ' all went well - return
  100.     Exit Sub
  101. onError:
  102.     MsgBox "error in TestForm.DumpCustomer"
  103. End Sub
  104. Private Sub cmdCreateObjects_Click()
  105.     Set myCustomers = CreateObject("AWCustomer.Customers")
  106.      
  107.     ' now that we have objects it makes sense to enable the other commands
  108.     cmdCreateObjects.Enabled = False
  109.     cmdLookupByLastName.Enabled = True
  110.     cmdLookupByID.Enabled = True
  111.     cmdGetFirstCustomer.Enabled = True
  112.     cmdGetNextCustomers.Enabled = True
  113.     cmdReleaseObjects.Enabled = True
  114.     ' all went well - return
  115.     Exit Sub
  116.      
  117. End Sub
  118. Private Sub cmdGetNextCustomers_Click()
  119.     If myCustomer.EOF Then
  120.         MsgBox "All the records have been displayed"
  121.     Else
  122.         DumpCustomer
  123.         myCustomer.MoveNext
  124.     End If
  125. End Sub
  126. Private Sub cmdReleaseObjects_Click()
  127.     On Error GoTo onError
  128.     Set myCustomer = Nothing
  129.     ' disable commands that don't make sense without objects
  130.     cmdCreateObjects.Enabled = True
  131.     cmdLookupByLastName.Enabled = False
  132.     cmdLookupByID.Enabled = False
  133.     cmdGetFirstCustomer.Enabled = False
  134.     cmdGetNextCustomers.Enabled = False
  135.     cmdReleaseObjects.Enabled = False
  136.     ' all went well - return
  137.     Exit Sub
  138. onError:
  139.     MsgBox "error in cmdReleaseObjects"
  140. End Sub
  141. Private Sub cmdLookupByLastName_Click()
  142.     Dim vLastName
  143.     On Error GoTo onError
  144.     vLastName = "White"
  145.     Set myCustomer = myCustomers.LookupCustomerByLastName(vLastName)
  146.     MsgBox "LookupByLastName succeeded"
  147.     Exit Sub
  148. onError:
  149.     MsgBox Err.Number & ": " & Err.Description
  150. End Sub
  151. Private Sub cmdLookupByID_Click()
  152.     Dim vID
  153.     vID = 3
  154.     On Error GoTo onError
  155.     Set myCustomer = myCustomers.LookupCustomerByID(vID)
  156.     MsgBox "LookupCustomerByID succeeded"
  157.     DumpCustomer
  158.     ' all went well - return
  159.     Exit Sub
  160. onError:
  161.     MsgBox "error in cmdLookupByID_Click"
  162. End Sub
  163. Private Sub cmdGetFirstCustomer_Click()
  164.     On Error GoTo onError
  165.     myCustomer.MoveFirst
  166.     DumpCustomer
  167.     ' all went well - return
  168.     Exit Sub
  169. onError:
  170.     MsgBox "error in cmdGetFirstCustomer_Click"
  171. End Sub
  172. Private Sub cmdExit_Click()
  173.       
  174.     End
  175. End Sub
  176.